<%--
 *  File:    DistributortenderRegionSelect.jsp
 *  @Author: Saraxia 
 *  Date:    2013/04/15
 *
 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/oval-tag.tld" prefix="oval" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<% //--------------------------------------  setting logger --%>
<%
  	Category cat = Category.getInstance("jsp.DistributortenderRegionSelect");  
%>

<% //--------------------------------------  variant and initialization --%>
<%
	String privilegeCode = "All";
	String strTableName = "ovregion";
	String strModuleName = "COM";
	String contextPath = request.getContextPath();

%>

<%
  	//get current userinfo
  	HashMap CurUserInfo = (HashMap)session.getAttribute("userinfo");
  	Integer nCurOrgId = (Integer)CurUserInfo.get("orgid");
  	String orgid = CurUserInfo.get("orgid").toString();
  	String strCurUserName = (String)CurUserInfo.get("username");
  	Integer nCurdoctorid = (Integer)CurUserInfo.get("doctorid");
  	String isPrimaryAdmin = (String)CurUserInfo.get("isprimaryadmin");
  	if(isPrimaryAdmin == null)
  	{
    	isPrimaryAdmin = "";
  	} 
  	//give permission
  	boolean bCanUpdatePrimaryAdmin = true;
  	if(!isPrimaryAdmin.equalsIgnoreCase("Y"))
  	{
    	bCanUpdatePrimaryAdmin = false;
  	} 
%>

  

<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>
<html>
<head>
<title>DistributortenderRegionSelect</title>
<PageFlow:CheckPageFlow pageName="regionselect"/>
<%@ include file="/inc/InitEdit.inc" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath %>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath %>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/FuncLib.js"></script>
<script language="JavaScript" src="../../js/SummaryDivision.js"></script>
<script>
isRunning=false;
</script>
<%@ include file="/inc/SummaryDivision.inc" %>
<%

  Vector regions = (Vector)pageContext.getAttribute("allregion");
  if(regions == null)
  {
	  regions = new Vector();
  }
  
  int totalsize  =  regions.size();
  
  
%>

<script language="JavaScript">

function clickRow(obj,idx)
{
  var cform = document.cform;
  cform.id.value = eval('obj.all.id'+idx).value;
}

function page_summary(actionvalue,orderbyname)
{
  var editform = summaryPrepare(cform,actionvalue,orderbyname);
  editform.action = "DistributortenderRegionSelect.jsp?<%= OvalTools.randomURL() %>";
  editform.target = "_self";
  isRunning = true;
  editform.submit();
}


function page_done(){
	   for(var i = 0; i <<%=totalsize%>; i++){ 
	    if(document.getElementById('regionid'+i).checked){
	      	if(isEmpty(document.cform.selectedregionid.value)){
	        	document.cform.selectedregionid.value = document.getElementById('regionid'+i).value;
	      	}else{
	      	    document.cform.selectedregionid.value = document.cform.selectedregionid.value + "," + document.getElementById('regionid'+i).value;;
	      	}
	        if(isEmpty(document.cform.selectedregioncode.value)){
	        	document.cform.selectedregioncode.value = document.getElementById('regioncode'+i).value;
	      	}else{
	        	document.cform.selectedregioncode.value = document.cform.selectedregioncode.value + "," + document.getElementById('regioncode'+i).value;;
	      	}
	      	if(isEmpty(document.cform.selectedregionname.value)){
	        	document.cform.selectedregionname.value = document.getElementById('regionname'+i).value;
	      	}else{
	        	document.cform.selectedregionname.value = document.cform.selectedregionname.value + "," + document.getElementById('regionname'+i).value;;
	      	}	      		      	
	      }
	   }
	   opener.page_setRegion(document.cform.selectedregionid.value,document.cform.selectedregioncode.value,document.cform.selectedregionname.value);  
	   window.close();
	}



function page_close(){
	window.close();
}

function clickCheckBox(obj){
	if(cform.numrows.value == 0){
		cform.selecteddisid.checked=obj.checked;
	}else if(cform.numrows.value >= 1){
		var j=0;
		for(var i=0;i<Number(cform.numrows.value);i++){
			var idchk=document.getElementById('regionid'+j);
			if(idchk){
				idchk.checked=obj.checked;
			}
			j++;
		}
	}
}

function clearCheckFlag(obj){
	if(!obj.checked){
		cform.checkallbox.checked=false;
	}
}


</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<form name="cform" method="post" action="<%=contextPath %>/Dispatcher"  target="_parent">

    <input type="hidden" name="pagename" value="regionselect">
    <input type="hidden" name="actionname">
    <input type="hidden" name="languagecode" value="<%=JspHelper.filterNull( session.getAttribute("languagecode") )%>">
    <input type="hidden" name="countrycode" value="<%=JspHelper.filterNull( request.getParameter("countrycode") )%>">
    <input type="hidden" name="numrows" value="<%=totalsize%>">
    
    <custom:hidden property="selectedregionid"/> 
	<custom:hidden property="selectedregioncode"/>
	<custom:hidden property="selectedregionname"/>
	
	<% //--------------------------------------  page location --%>
	<%@ include file="/inc/PageLocation.inc" %>
	
	<table width="100%" cellspacing="0" cellpadding="0" border="0">
        
		  <tr>
		      <td class="summary_top">
		          <table width="100%" border="0" cellspacing="0">
		      	   <%@ include file="/inc/SummarySearch.inc" %>
		          </table>
		      </td>
		  </tr>        
   <tr>
    <td> 
      <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
    <tr class="deepblue-left" >
	  <td width="5%" class="title_center">
				<%if(totalsize > 0){ %>
					<input type="checkbox" name="checkallbox" class="checkbox"  onclick="clickCheckBox(this)">
				<%}else{ %>
					&nbsp;
				<%} %>
	  </td>
      <td class="title_center" width="60" nowrap><%= label.getLabelName("L_AreaCode") %></td>
      <td class="title_center"><%= label.getLabelName("L_AreaName") %></td>
    </tr>

     <%
        int i = 0;
        String strIsChecked = new String("Checked");
        String strClassType = new String();   
        String strRegionCode = "";     
        String strRegionName = "";
        Integer nRegionid = new Integer("-1");
     %>
     <logic:iterate id="region" collection="<%= regions %>" indexId="idx">                      
     <%
       HashMap regionMap = (HashMap)pageContext.getAttribute("region"); 
       if(i%2 == 1)
       {
         strClassType = "td-listrom";
       }else{                    
         strClassType = "";
       }
       if(i != 0)
       {          
         strIsChecked = "";
       }
       else
       {
         strRegionCode = (String)(regionMap.get("regioncode"));         
         strRegionName = (String)(regionMap.get("regionname"));
         nRegionid = (Integer)(regionMap.get("regionid"));
       }  
       i++;        
     %>   
   <tr onMouseOver="this.className='tr-over'" onMouseOut="this.className='<%=JspHelper.filterNull( strClassType )%>'"  class="none"> 
      <td>
            <input id="regionid<%=idx %>" type="checkbox" name="deptid" value="<%=JspHelper.filterNull(regionMap.get("regionid"))%>" class="checkbox" onclick="clearCheckFlag(this)">
      </td>
   	<td>
     		<custom:write name="region" property="regioncode" nbsp="true"/>
     </td>
     <td>
     		<custom:write name="region" property="regionname" nbsp="true"/>
     </td>  
     
     		<custom:hidden name="region" property="regioncode" colIndex="<%= idx %>"  />
            <custom:hidden name="region" property="regionname" colIndex="<%= idx %>" />
              
	</tr>
    </logic:iterate> 
 
         <%@ include file="/inc/SummaryActionPop.inc" %>
      </table>
        <table width="100%" cellspacing="0" cellpadding="0">
          <tr> 
            <td class="summary_top"></td>
          </tr>
          <tr> 
              <td class="td_center">
                <a onclick="page_done();"><custom:button type="1" label="L_Ok" imgsrc="add.gif" border="0" style="width:60"/></a>
              	<a onclick="page_close();"><custom:button type="1" label="L_Close" imgsrc="close.gif" border="0" style="width:60"/></a>
              </td>
          </tr>
        </table>
      </td>
    </tr>
</table>
</form>
</body>
</html>
<script>
isRunning=false;
</script>


